package listener;

import Interceptor.MyWebSocketInterceptor;
import handle.WebSocketPushHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * Created by asus on 2018/11/20.
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig extends WebMvcConfigurerAdapter  implements WebSocketConfigurer {
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        webSocketHandlerRegistry.addHandler(WebSocketPushHandler(), "/webSocketServer.do").addInterceptors(new MyWebSocketInterceptor()).setAllowedOrigins("*");
       webSocketHandlerRegistry.addHandler(WebSocketPushHandler(), "/sockjs/webSocketServer.do").addInterceptors(new MyWebSocketInterceptor()).withSockJS();
    }

    @Bean
     public WebSocketHandler WebSocketPushHandler() {
            return new WebSocketPushHandler();
     }

}
